package com.heima.wemedia.config;

import com.heima.common.constants.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 声明 演示发布文章所需的所有交换机队列 和绑定关系
 */
@Configuration
public class DeclarePubArticleRabbitConfig {

    @Bean
    Queue publishArticlequeue(){
        return QueueBuilder.durable(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE).build();
    }

    @Bean
    DirectExchange delayExchange(){
        DirectExchange directExchange = new DirectExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE);
        directExchange.setDelayed(true);
        return directExchange;
    }

    @Bean
    Binding binding(){
        return BindingBuilder.bind(publishArticlequeue()).to(delayExchange()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }
}
